home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 31 / Amiga Format CD31 (1998-09-02)(Future Publishing)(GB)(Track 1 of 2)[!][issue 1998-10].iso / -seriously_amiga- / sound / aplayer / files / arexx / toiff.aplay < prev    next >
Text File  |  1998-07-16  |  3KB  |  105 lines

  1. /* This script will convert all files in a directory to IFF-8SVX files */
  2.  
  3. OPTIONS RESULTS
  4.  
  5. PARSE ARG dir
  6.  
  7. IF dir="" THEN DO
  8.     SAY "Usage: rx ToIFF.aplay <directory>"
  9.     SAY
  10.     SAY "This script will convert all your files specified with"
  11.     SAY "the <directory> parameter to IFF-8SVX files."
  12.     SAY "It can only handle files up to 64Kb."
  13.     EXIT
  14. END
  15.  
  16. /* Add the functions of the 'rexxsupport.library' */
  17.     IF ADDLIB('rexxsupport.library',0,-30,0) = 0 THEN DO
  18.         IF SHOW('L','rexxsupport.library') = 0 THEN DO
  19.             SAY "Couldn't open rexxsupport.library"
  20.             EXIT 10
  21.         END
  22.     END
  23.  
  24. /* Read the directory into a string */
  25. dirlist=SHOWDIR(dir,'F',';')||';'
  26.  
  27. IF RIGHT(dir,1)~=':' & RIGHT(dir,1)~='/' THEN
  28.     dir=dir||'/'
  29.  
  30. /* Begin to convert the files */
  31. IF dirlist~=';' THEN DO
  32.     DO UNTIL dirlist=''
  33.         filename=dir||LEFT(dirlist,INDEX(dirlist,';')-1)
  34.         SAY "Computing "||filename
  35.  
  36.         /* Test file for a IFF-File */
  37.         IF OPEN(rdfile,filename,'R') THEN DO
  38.             test=READCH(rdfile,4)
  39.             IF test~="FORM" THEN DO
  40.                 filelen=SEEK(rdfile,0,'E')
  41.                 IF filelen<65535 THEN DO
  42.                     IF OPEN(wrfile,filename||'.temp','W') THEN DO
  43.                         WRITECH(wrfile,"FORM")
  44.  
  45.                         temp=D2X(filelen+40)
  46.                         temp=INSERT("",temp,0,8-LENGTH(temp),'0')
  47.                         WRITECH(wrfile,X2C(temp))
  48.  
  49.                         WRITECH(wrfile,"8SVXVHDR")
  50.                         WRITECH(wrfile,X2C('00000014'))
  51.  
  52.                         hexlen=D2X(filelen)
  53.                         hexlen=INSERT("",hexlen,0,8-LENGTH(hexlen),'0')
  54.                         WRITECH(wrfile,X2C(hexlen))
  55.  
  56.                         WRITECH(wrfile,X2C('00000000'))
  57.                         WRITECH(wrfile,X2C('00000020'))
  58.                         WRITECH(wrfile,X2C('40BE'))
  59.                         WRITECH(wrfile,X2C('0100'))
  60.                         WRITECH(wrfile,X2C('00010000'))
  61.  
  62.                         WRITECH(wrfile,"BODY")
  63.                         WRITECH(wrfile,X2C(hexlen))
  64.  
  65.                         /* Copy the file */
  66.                         mem=ALLOCMEM(filelen)
  67.                         IF mem~='0'x THEN DO
  68.                             CALL SEEK(rdfile,0,'B')
  69.                             CALL EXPORT(mem,READCH(rdfile,filelen),filelen)
  70.                             WRITECH(wrfile,IMPORT(mem,filelen))
  71.                             FREEMEM(mem,filelen)
  72.                             CLOSE(rdfile)
  73.                             CLOSE(wrfile)
  74.                             CALL DELETE(filename)
  75.                             CALL RENAME(filename||'.temp',filename)
  76.                         END
  77.                         ELSE DO
  78.                             SAY "^^^^^^Out of memory^^^^^^"
  79.                         CLOSE(wrfile)
  80.                         CLOSE(rdfile)
  81.                         CALL DELETE(filename||'.temp')
  82.                         END
  83.                     END
  84.                     ELSE DO
  85.                         CLOSE(rdfile)
  86.                         SAY "^^^^^^Couldn't open temp file^^^^^^"
  87.                     END
  88.                 END
  89.                 ELSE DO
  90.                     CLOSE(rdfile)
  91.                         SAY "^^^^^^File too big^^^^^^"
  92.                 END
  93.             END
  94.             ELSE DO
  95.                 CLOSE(rdfile)
  96.                 SAY "^^^^^^File already an IFF file^^^^^^"
  97.             END
  98.         END
  99.         ELSE DO
  100.             SAY "^^^^^^Couldn't open file^^^^^^"
  101.         END
  102.         dirlist=DELSTR(dirlist,1,INDEX(dirlist,';'))
  103.     END
  104. END
  105.